<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '出入库统计汇总',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

<!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <script type="text/javascript">
    	$(".js-sidebar-nav>li:nth-child(11)>ul").show(80);
    	$(".js-sidebar-nav>li:nth-child(11)>a>span").addClass("sidebar-nav-sub-ico-rotate");
    	$(".js-sidebar-nav>li:nth-child(11)>ul>li:nth-child(2)>a").addClass("active");
    </script>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">

        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">出入库统计汇总</div>
                        </div>
                        <div class="widget-body  am-fr">
                            <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">
                                <div class="am-btn-toolbar">
                                    <div class="am-g">
                                        <div class="am-u-sm-12 am-u-md-6 am-form-group">
                                            <button type="button" class="am-btn am-btn-default am-margin-right" id="my-start">开始日期</button><span id="my-startDate">2014-12-20</span>
                                        </div>
                                        <div class="am-u-sm-12 am-u-md-6 am-form-group">
                                            <button type="button" class="am-btn am-btn-default am-margin-right" id="my-end">结束日期</button><span id="my-endDate">2014-12-25</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">

                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-6">
                                    <div class="am-form-group am-input-group am-input-group-sm tpl-form-border-form cl-p">
    <!--                                    <form action="/admin/user/search" method="get">-->
                                        <input type="text" class="am-form-field" name="search" id="search">
                                        <span class="am-input-group-btn">
                                            <a href="javascript:void(0)" onclick="search123()" class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search">搜索</a>
                                        </span>
    <!--                                    </form>-->
                                    </div>
                                </div>
                                
                            </div>                            
                            <div class="am-u-sm-12 am-form-group ">
                                <div class="am-btn-toolbar am-u-sm-12">
                                    <div class=" am-btn-group-xs">
                                        <?php
                                        $type = isset($_GET['type']) ? $_GET['type'] : 'goods';
                                        ?>
                                        <a href="javascript:void(0);" onclick="dai()" class="am-btn   <?php if($type == 'goods'){echo 'am-btn-primary';}  else {echo 'am-btn-default';}?> ">按商品</a>
                                        <a href="javascript:void(0);" onclick="yi()" class="am-btn  <?php if($type == 'gys'){echo 'am-btn-primary ';} else {echo 'am-btn-default';}?> ">按供应商</a>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-form-group ">
                                <div class="am-btn-toolbar am-u-sm-12">
                                    <div class=" am-btn-group-xs">
                                        <a href="javascript:void(0);" onclick="" class="am-btn am-btn-primary"><span class="am-icon-download"></span> 导出</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                            <table class="am-table am-table-compact am-table-striped tpl-table-black " id="accordion">
                                <thead>
        					        <tr>
        					            <th>序号</th>
        					            <th>商品编码</th>
        					            <th>商品名称</th>
        					            <th>商品规格</th>
        					            <th>商品来源</th>
        					            <th>商品分类</th>
        					            <th>合计出库数量</th>
        					            <th>合计入库数量</th>
        					        </tr>
        					    </thead>
        					    <tbody class="am-panel am-panel-default">
                                <?php
                                //                                    print_r($list);
                                //                                    die();
                                if(isset($list) && $list){
                                    foreach ($list as $v) {
                                        //                                        2物料包、3书籍、4机器耗材、9打印机租赁、8供应商商品
                                        $dataId = $v['ckId'] ? $v['ckId'] : $v['id'];
                                        echo '<tr class="gradeX">
                                                         <td data-id="'.$dataId.'">'.$v['id'].'</td>
                                                         <td>'.$v['product_no'].'</td>
                                                         <td>'.$v['name'].'</td>';
                                        if(isset($v['isSpecification']) && $v['isSpecification'] == 1){
                                            echo '<td><button type="button" class="am-btn am-btn-default am-radius specification-btn" data-am-modal="{target: \'#addSpecification\', closeViaDimmer: 0, width: 500, height: 400}">商品规格+</button></td>';
                                        }else{
                                            echo '<td></td>';
                                        }

                                        switch ($v['source']){
                                            case 'ist':
                                                echo '<td>爱思特</td>';
                                                break;
                                            case '51ck':
                                                echo '<td>51ck</td>';
                                                break;
                                        }

                                        switch ($v['one_category']){
                                            case 2:
                                                echo '<td>物料包</td>';
                                                break;
                                            case 3:
                                                echo '<td>书籍</td>';
                                                break;
                                            case 4:
                                                echo '<td>机器耗材</td>';
                                                break;
                                            case 8:
                                                echo '<td>供应商商品</td>';
                                                break;
                                            case 9:
                                                echo '<td>打印机租赁</td>';
                                                break;
                                        }

                                        echo '<td>'.$v['quantity'].'</td>
                                                      <td>'.$v['priceAll'].'</td>';

                                    }
                                }else{
                                    if(isset($gyslist) && $gyslist){

                                    }else{
                                        echo '暂无数据';
                                    }
                                }

                                ?>
                				</tbody>
                        	</table>
                        </div>
                        <div class="am-u-lg-12">
                            <div class="am-u-sm-centered">
                                <ul class="am-pagination am-pagination-centered" id="paging">

                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 模态框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="addSpecification">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">规格值详情
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <table class="am-table am-table-bordered am-table-radius am-table-striped am-table-hover">
                <thead>
                <tr>
                    <th style="width: 50%">规格值</th>
                    <th style="width: 50%">单品编码</th>
                </tr>
                </thead>
                <tbody class="specification-box">

                </tbody>
            </table>
        </div>
        <div class="btn-box">
            <button type="button" class="am-btn am-btn-primary" id="confirmSpecification" data-am-modal-close>确认</button>
        </div>

    </div>
</div>



<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/page.js"></script>

<script>
    $(function() {

        $(document).on("click",".specification-btn",function(){
            var thisTr = $(this).parents(".gradeX");                        //点击的本行tr
            var productId = thisTr.children("td:first-child").data("id");   //传给后台的商品ID
            console.log(productId)

            var specificationBox = $(".specification-box");

//        specificationBox.empty();
            $.ajax({
                url:"/api/goods/getGoodsIdByData",
                data:{
                    productId:productId
                },
                dataType:"json",
                type:"post",
                success:function(data){
//                console.log(data);
                    var tr = "";
                    for(var i = 0;i < data.length; i++) {
                        tr += '<tr>'
                            +'<td>'+ data[i].specification_group_names + '</td>'
                            +'<td>'+ data[i].group_no + '</td>'
                            + '</tr>';
                    }

                    specificationBox.html(tr);
                },
                error:function(data){
                    console.log(data);
                }
            });
        });

        var startDate = new Date(2014, 11, 20);
        var endDate = new Date(2014, 11, 25);
        var $alert = $('#my-alert');
        $('#my-start').datepicker().
        on('changeDate.datepicker.amui', function(event) {
            if (event.date.valueOf() > endDate.valueOf()) {
                $alert.find('p').text('开始日期应小于结束日期！').end().show();
            } else {
                $alert.hide();
                startDate = new Date(event.date);
                $('#my-startDate').text($('#my-start').data('date'));
            }
            $(this).datepicker('close');
        });

        $('#my-end').datepicker().
        on('changeDate.datepicker.amui', function(event) {
            if (event.date.valueOf() < startDate.valueOf()) {
                $alert.find('p').text('结束日期应大于开始日期！').end().show();
            } else {
                $alert.hide();
                endDate = new Date(event.date);
                $('#my-endDate').text($('#my-end').data('date'));
            }
            $(this).datepicker('close');
        });
    });
</script>

<script>
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    function dai() {
        var search = GetQueryString('search');
        // $(".am-btn-primary").removeClass("am-btn-primary");
        // $(this).addClass("am-btn-primary");

        if(search == null){
            window.location.href='?page=1'+'&type=goods'
        }else{
            window.location.href='?page=1'+'&search='+search+'&type=goods'
        }
    }
    function yi() {
        var search = GetQueryString('search');
        if(search == null){
            window.location.href='?page=1'+'&type=gys'
        }else{
            window.location.href='?page=1'+'&search='+search+'&type=gys'

        }
    }
</script>

<script>
    $(document).ready(function() {
        //设置分页信息
        var pageOptions = {
            AllowPaging: true,
            PageIndex: <?php echo $_GET['page'] ?>,      //设置当前页码
            PageSize: <?php echo $pageNum ?>,       //设置分页大小
            RecordCount: <?php echo $totalNum ?>,  //设置数据总数
            // TotalPage: ,      //设置总页数
            showPageCount: 4,
            onPageClick: function(pageIndex) {
                var page = parseInt(pageIndex);

                window.location.href = "?page="+ page;


            }
        }
        //初始化分页栏
        $('#paging').pageBar(pageOptions);
    })
</script>

</body>
</html>